package com.ocm.tourism.core.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.TableGenerator;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Configurable
public class Advertisement {

   @Size(max = 4000)
   private String content;

   @Size(max = 255)
   private String title;

   @NotNull
   @DateTimeFormat(pattern="dd/MM/yyyy")
   private Date startDate;

   @NotNull
   @DateTimeFormat(pattern="dd/MM/yyyy")
   private Date endDate;

   @NotNull
   private Boolean forever;

   @NotNull
   @Enumerated(EnumType.STRING)
   private Priority priority;

   private Boolean actived;

   private Date modifiedDate;

   public String toString() {
      return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
   }
   
   @Id
   @GeneratedValue(strategy=GenerationType.TABLE,generator="GEN_ADVERTISEMENT")
   @TableGenerator(name = "GEN_ADVERTISEMENT", table = "SEQUENCE_LIST", allocationSize = 1, initialValue = 1, pkColumnName = "NAME", valueColumnName = "NEXT_SEQUENCE", pkColumnValue = "ADVERTISEMENT")
   private Long id;

   @Version
   @Column(name = "version")
   private Integer version;

   public Long getId() {
      return this.id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public Integer getVersion() {
      return this.version;
   }

   public void setVersion(Integer version) {
      this.version = version;
   }

   public String getContent() {
      return content;
   }

   public void setContent(String content) {
      this.content = content;
   }

   public String getTitle() {
      return title;
   }

   public void setTitle(String title) {
      this.title = title;
   }

   public Date getStartDate() {
      return startDate;
   }

   public void setStartDate(Date startDate) {
      this.startDate = startDate;
   }

   public Date getEndDate() {
      return endDate;
   }

   public void setEndDate(Date endDate) {
      this.endDate = endDate;
   }

   public Boolean getForever() {
      return forever;
   }

   public void setForever(Boolean forever) {
      this.forever = forever;
   }

   public Priority getPriority() {
      return priority;
   }

   public void setPriority(Priority priority) {
      this.priority = priority;
   }

   public Boolean getActived() {
      return actived;
   }

   public void setActived(Boolean actived) {
      this.actived = actived;
   }

   public Date getModifiedDate() {
      return modifiedDate;
   }

   public void setModifiedDate(Date modifiedDate) {
      this.modifiedDate = modifiedDate;
   }

   @Override
   public boolean equals(Object obj) {
      Advertisement room = (Advertisement) obj;
      if (room.getId()!=null && this.getId()!=null){
         return room.getId().longValue() == this.getId().longValue();
      }
      return super.equals(obj);
   }
}
